package com.ys.web.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ys.web.dao.CommonDao;
import com.ys.web.entity.PromotionPlan;
import com.ys.web.service.PromotionPlanService;

/**
 * 推广计划-Service-实现类
 * @author wdj
 *
 */
@Service("promotionPlanService")
@Transactional
public class PromotionPlanServiceImpl implements PromotionPlanService {

	@Autowired
	private CommonDao commonDao;

 	/**
 	 * 批量新增
 	 * @param entitys
 	 */
	@Override
	public void batchSave(List<PromotionPlan> entitys) {
		commonDao.batchSave(entitys);
	}
	
 	/**
 	 * 根据accountId和planName查找唯一推广计划
 	 * @param companyId 代运营公司ID
 	 * @param planName 推广计划名称
 	 * @return true:存在，false：不存在
 	 */
	public Boolean ifExistPromotionPlan(Integer companyId, String planName) {
			String hql = " from PromotionPlan where companyId = ? and planName = ?";
			List<PromotionPlan> list = commonDao.findHql(hql, companyId, planName);
			if(list.isEmpty()) {
				return false;
			}
			else {
				return true;				
			}	
	}

	/**
	 * 根据公司id查找对应推广计划
	 * @param companyId 公司id
	 * @return 对应推广计划列表
	 */
	public List<Map<String,String>> getPlanToSelect(Integer companyId) {
		List<Map<String,String>> promoteList = new ArrayList<Map<String,String>>();
		List<PromotionPlan> list =commonDao.findByProperty(PromotionPlan.class, "companyId", companyId);			

		for (PromotionPlan promotionPlan : list) {
			Map<String, String> promoteMap = new HashMap<>();
			promoteMap.put("promotePlan", promotionPlan.getPlanName());
			promoteList.add(promoteMap);
		}
			
		return promoteList;
	}
	
	
}
